﻿/*<summary>
Created By : Swati
Created On : 10/18/2008
Class Name : Procedure_Mapper
Used In    : 
------------------------------------------------------------------------
Modification Log  
------------------------------------------------------------------------
Created By        Modified By         Remarks                             
-----------       ------------        ----------------------------------
                                                                          
------------------------------------------------------------------------
</summary>*/

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Utils;

namespace RegistrationController
{
    public class Procedure_Mapper
    {
        public bool set_procedure(ProcedureDetails objProcedure)
        {
            if (objProcedure != null)
            {
                bool bresult;
               
                try
                {
                    SqlParameter outID = new SqlParameter("@biOutID", SqlDbType.BigInt);
                    outID.Direction = ParameterDirection.Output;
                    SqlParameter outProcDate = new SqlParameter("dtOutProcedureDate", SqlDbType.DateTime);
                    outProcDate.Direction = ParameterDirection.Output;
                    SqlParameter retval = new SqlParameter("@retVal", SqlDbType.Int);
                    retval.Direction = ParameterDirection.ReturnValue;
                    hpm_ezUtilsAdapter.executeNonQuery("SP_SetPatientProcedureDetail",
                    retval,
                    new SqlParameter("@biID", objProcedure.ID),
                    new SqlParameter("@biCRN", objProcedure.CRNumber),
                    new SqlParameter("@vchProcedure", objProcedure.ProcedureName),
                    new SqlParameter("@vchConsultant", objProcedure.Consultant),
                    new SqlParameter("@vchReceiptID", objProcedure.ReceiptID),
                    new SqlParameter("@vchRemarks", objProcedure.Remarks),
                    new SqlParameter("@bPaid", objProcedure.Paid),
                    outID,
                    outProcDate);
                    
                    if (Convert.ToInt16(retval.Value) == 0) 
                    { 
                        objProcedure.ID = Convert.ToString(outID.Value);
                        objProcedure.ProcedureDate = Convert.ToString(outProcDate.Value);
                        bresult = true; 
                    } else 
                    {
                        bresult = false; 
                    } 
                    
                    return bresult;
                }
                catch (SqlException ex)
                {
                    string errorMessage = string.Format(
                        "An Error Occurred While Loading the Procedure Information to the DB. Message: {0}", ex.Message);
                    //throw new MappingException(errorMessage, ex);}
                    return false;
                }
                finally
                {
                    //DBL.Dispose();
                }
            }

            else { return false; }
        }

        public void Dispose()
        {
            this.Dispose(true);
            System.GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
        }
    }
}